import { UserProfilesAPI } from '../../request/api'
export default {
    namespaced: true,
    state: {
        cartTotal: 0,
        userInfo: {
            nickName: "游客",
            coin: 0,
            //图片路径抽取了之后当成模块使用
            headImg: require("../../assets/img/userImg.f8bbec5e.png")
        }
    },
    mutations: {
        chenUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal;
            state.userInfo = payload.userInfo
        },
        initUserInfo(state) {
            state.cartTotal = 0;
            state.userInfo = {
                    nickName: "游客",
                    coin: 0,
                    //图片路径抽取了之后当成模块使用
                    headImg: require("../../assets/img/userImg.f8bbec5e.png")
                }
        }
    },
    actions: {
        async asyncChenUserInfo({ commit }) {
            let userInofRer = await UserProfilesAPI();
            //调用隐藏mutations中的方法,同时把数据传进payload
            commit("chenUserInfo", userInofRer.data)
        }
    }
}